import boqdoc
from _wizard import *
from _page import Page

class Wiz(Wizard):
   def __init__(self):
      Wizard.__init__(self, "Add Schedule")

   def __call__(self):
      self.pages[0] = Page(self, "Schedule Name")
      self.pages[1] = Page(self, "Insert Before")

      schlist = [ sch.name for sch in wx.GetApp().GetDoc().schedules ]
      schlist += ["<Insert at end>"]

      self.txtname = wx.TextCtrl(self.pages[0], wx.ID_ANY, "")
      self.lstschedules = wx.ListBox(self.pages[1], wx.ID_ANY, choices=schlist)

      self.pages[0].AddText("Enter the name of the new schedule")
      self.pages[0].AddWidget(self.txtname)
      self.pages[0].SetNext(self.pages[1])

      self.pages[1].AddText("Insert before")
      self.pages[1].AddWidget(self.lstschedules)
      self.pages[1].SetPrev(self.pages[0])

      return self.run()

   def complete(self):
      beforesch = self.lstschedules.GetSelections()
      beforesch += (len(doc().schedules), 0)
      schedule = boqdoc.Schedule(self.txtname.GetValue(), doc())
      doc().schedules.insert(beforesch[0], schedule)
